import DAO.BookDao;
import entity.Book;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.testng.annotations.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;


public class hello {

    @Test
    public void test01() throws IOException {
        //创建一个流
        InputStream is= Resources.getResourceAsStream("mybatis-config.xml");
        //创建工厂
        SqlSessionFactory factory=new SqlSessionFactoryBuilder().build(is);
        //获得连接对象
        SqlSession sqlSession = factory.openSession();
        //通过连接对象获得接口实现对象
        BookDao bookDao = sqlSession.getMapper(BookDao.class);
        List<Book> books = bookDao.findAll();
        System.out.println("查询所有记录");
        System.out.println(books);
        String id="2";
        Book booksid = bookDao.findById(id);
        System.out.println("查询id为"+id+"的记录");
        System.out.println(booksid);
    }
}